/* xx1.9.xcim.p - Gen CIM for ECN setup (from eb2.1 to 2015EE)
   Created By: Hayden (2015EE) 2016-06-13
   
   Purpose: Generate CIM for 2015EE ECN Setup base on eb2.1
   Runtime: eb2.1
   Cimload: 2015EE
   
   Upgrade Step:
     1. run program in eb2.1 generate *.cim files
     2. ftp *.cim files to 2015ee
     3. doing cimload in each domain by cim file prefix
*/

def var outname     as char format 'x(12)' init '1.9.x-ecn' label 'Out File'.
def var outfile_prc as char format 'x(20)'.
def var outfile_hk  as char format 'x(20)'.

{mfdtitle.i}
def var DOMAIN_PRC as char init 'PRC'.
def var DOMAIN_HK  as char init 'HK' .

repeat:
  disp 'Generate CIM for 2015EE ECN Setup base on eb2.1' skip(1)
       'Upgrade Steps:' skip
       '  1. run program in eb2.1 generate *.cim files' skip
       '  2. ftp *.cim files to 2015ee' skip
       '  3. doing cimload in each domain by cim file prefix' skip(1)
       outname colon 14 '.cim' space(2) outfile_prc no-label view-as text
                               space(2) outfile_hk  no-label view-as text skip
  with frame a width 80 side-label.
  
  prompt-for outname with frame a editing:
    if frame-field = 'outname' then do:
      if input outname <> "" then do:
        disp DOMAIN_PRC + '-' + input outname + '.cim' @ outfile_prc with frame a.
        disp DOMAIN_HK  + '-' + input outname + '.cim' @ outfile_hk  with frame a.
      end.
      else do:
        disp '' @ outfile_prc with frame a.
        disp '' @ outfile_hk  with frame a.
      end.
    end.
    status input.
    readkey.
    apply lastkey.
  end.
  
  outname = input outname.
  
  if outname = "" then do:
    message 'Error: Please enter all filenames'.
    next.
  end.
  
  outfile_prc = DOMAIN_PRC + '-' + outname  + '.cim'.
  outfile_hk  = DOMAIN_HK  + '-' + outname  + '.cim'.

  os-delete value(outfile_prc).
  output to value(outfile_prc).
  
  /* setup 1.9.24 PCC Control */
  find first pcc_ctrl where pcc_domain = global_domain no-lock no-error.
  if available(pcc_ctrl) then do:    
    put '@@batchload pcpcpm.p' skip.
    put unformatted '"' pcc_auto_nbr '" "' pcc_security_on '" "' pcc_enforce_seq '"' skip.
    put unformatted                           pcc_next_pco[1]
                    ' "' pcc_pco_pre[2]  '" ' pcc_next_pco[2]
                    ' "' pcc_pco_pre[3]  '" ' pcc_next_pco[3]
                    ' "' pcc_pco_pre[4]  '" ' pcc_next_pco[4]
                    ' "' pcc_pco_pre[5]  '" ' pcc_next_pco[5]
                    ' "' pcc_pco_pre[6]  '" ' pcc_next_pco[6]
                    ' "' pcc_pco_pre[7]  '" ' pcc_next_pco[7]
                    ' "' pcc_pco_pre[8]  '" ' pcc_next_pco[8]
                    ' "' pcc_pco_pre[9]  '" ' pcc_next_pco[9]
                    ' "' pcc_pco_pre[10] '" ' pcc_next_pco[10]
                    ' "' pcc_pco_pre[11] '" ' pcc_next_pco[11]
                    ' "' pcc_pco_pre[12] '" ' pcc_next_pco[12] skip.
    put unformatted '-' skip.
    put unformatted '-' skip.
    put '@@end' skip.
  end.
  
  put skip(1).
  
  /* setup 1.9.1.1 Group Maintenance  */
  for each pcl_mstr where pcl_domain = global_domain no-lock:
    put '@@batchload pcgrmt.p' skip.
    put unformatted '"' upper(pcl_group) '"' skip.
    put unformatted '"' pcl_desc '"' skip.
    put '@@end' skip.
  end.
  
  put skip(1).
  
  /* setup 1.9.1.5 Routing Slip Maintenance */
  for each rst_mstr where rst_domain = global_domain no-lock:
    put '@@batchload pcrsmt.p' skip.
    put unformatted '"' rst_appr_code '"' skip.
    put unformatted '"' rst_desc '" "' rst_svrty_list '" "' rst_notify1 '" "' rst_notify1_mail '" "' rst_notify2 '" "' rst_notify2_mail '"' skip.
    if rst_appr_code = 'ECN' then do:
      put '"ENGM"' skip.
      put unformatted 10 ' ' 10 ' ' '"NO" "NO"' skip.
    end.
    put '@@end' skip.
  end.
  
  put skip(1).
  
  /* setup 1.9.1.9 PCR/PCO Type Maintenance */
  for each pct_mstr where pct_domain = global_domain no-lock:
    put '@@batchload pctypemt.p' skip.
    put unformatted '"' pct_type '" "' pct_dsgn_grp '"' skip.
    put unformatted '"' pct_desc '" "' pct_doc_type '" "' pct_prefix '" "' pct_approval '" "' pct_distr '"' skip.
    put '@@end' skip. 
  end.
  
  output close.
  
  /* copy outfile_prc to outfile_hk */
  os-delete value(outfile_hk).
  os-copy   value(outfile_prc) value(outfile_hk).
  
  message 'Completed!'.
  
end.
